public class IsPalindrome2 {

    public boolean isPalindrome(ListNode head) {
        if (head.next == null) return true;
        StringBuffer sb = new StringBuffer();
        ListNode temp = head;
        while (temp != null) {
            sb.append(temp.val + "");
            temp = temp.next;
        }
        if (sb.toString().equals(sb.reverse().toString())) return true;
        return false;
    }
}
